package ch.sv7.tool.dbmanager.db.fix;

import ch.sv7.tool.dbmanager.db.ColumnSchema;
import ch.sv7.tool.dbmanager.db.SchemaElement;
import ch.sv7.tool.dbmanager.db.dialect.DialectException;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class RenameColumnFix extends AbstractSchemaFix {


	private ColumnSchema columnSchema;
	private String newName;

	/**
	 * @param missingColumnDifference
	 */
	public RenameColumnFix(ColumnSchema columnSchema, String newName) {
		super();
		this.columnSchema = columnSchema;
		this.newName = newName;
	}

	public SchemaElement getActionTarget() {
		return columnSchema;
	}
	
	public String getSQLFix() throws DialectException {
		String ddl = "\n-- Rename column Fix \n";
		ddl += getDialect().getRenameColumnDDL(columnSchema, newName);
		return ddl;
	}

	public int getPriority() {
		return SchemaFix.PRIORITY_COLUMN_RENAME;
	}

	public String getDescription() {
		return "Rename column " 
		+ columnSchema.getTable().getName() 
		+ "." 
		+ columnSchema.getName() + " to " + newName;
	}

	public int getAction() {
		return ACTION_EDIT;
	}
	
}
